package br.com.absolutech.study.chapter6.pag261;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class SuperNotSerial {

	public static void main(String[] args) {
		Dog d = new Dog(35, "Fido");
		System.out.println("before: " + d.name + " " + d.weight);

		try {
			FileOutputStream fs = new FileOutputStream("resources/testSer261.ser");
			ObjectOutputStream os = new ObjectOutputStream(fs);
			os.writeObject(d);
			os.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		try {
			FileInputStream fs = new FileInputStream("resources/testSer261.ser");
			ObjectInputStream ois = new ObjectInputStream(fs);
			d = (Dog) ois.readObject();
			ois.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("after: " + d.name + " " + d.weight);

	}
}

@SuppressWarnings("serial")
class Dog extends Animal implements Serializable {
	String name;

	Dog(int w, String n) {
		weight = w;
		name = n;
	}
}

class Animal {
	int weight = 42;
}
